package cn.niit.letuseatdemo.controller.api;


import cn.niit.letuseatdemo.entity.vo.response.BaseResponse;
import cn.niit.letuseatdemo.exception.LetuseatException;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestController;

@Slf4j
@RestController
public abstract class BaseApiController {

    @ExceptionHandler(value = RuntimeException.class)
    public BaseResponse handleRuntimeException(RuntimeException e){
        log.error("BaseApiController.handleRuntimeException 捕获到了异常：{}", e);
        // TODO 处理逻辑：当程序发生异常后，需要如何处理
        return BaseResponse.error("999999", e.getMessage());
    }

  /*
  * @Description: 捕获自定义异常
  * @Author: Zhang Shiqi
  * @CreateTime： 2022/12/7 17:44
   * @param: e
   * @return: cn.niit.letuseatdemo.entity.vo.response.BaseResponse
  **/
  @ExceptionHandler(value = LetuseatException.class)
    public BaseResponse handleHospitalException(LetuseatException e){
        log.error("BaseApiController.LetuseatException 捕获到了异常：{}", e);
        return BaseResponse.error(e.getCode(), e.getMessage());
    }

//    @ExceptionHandler(value = ArithmeticException.class)
//    public BaseResponse arithmeticException(ArithmeticException e){
//        log.error("BaseApiController.ArithmeticException 捕获到了异常：{}", e.getMessage());
//        return BaseResponse.error("999999", e.getMessage());
//    }

}
